Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: More Macintosh Toolbox

Previous | Chapter Top | Chapter Contents | Next |

Using a Component

Once you have established a connection to a component, you can use its services.

Each time you call a component routine, you must specify the component instance that identifies your connection and provide any other parameters as required by the routine.

For example, Listing 4 illustrates the use of a drawing component. The application-defined procedure establishes a connection to a drawing component, calls the component's DrawerSetup function to establish the rectangle in which to draw the desired object, and then draws the object using the DrawerDraw function.

Listing 4 Using a drawing component

PROCEDURE MyDrawAnOval (VAR aDrawOvalComp: ComponentInstance);
VAR
    r:                  Rect;
    result:             ComponentResult;
BEGIN
    {open a connection to a drawing component}
    aDrawOvalComp := OpenDefaultComponent('draw', 'oval');
    IF aDrawOvalComp <> NIL THEN
    BEGIN
        SetRect(r, 40, 40, 80, 80);                 
        {set up rectangle for oval}
        result := DrawerSetup(aDrawOvalComp, r);
        IF result = noErr THEN                      
            result := DrawerDraw(aDrawOvalComp);{draw oval}
    END;
END;

If you specify an invalid connection as a parameter to a component routine, the Component Manager sets the function result of the component routine to badComponentInstance .

Each component type supports a defined set of functions. You must refer to the appropriate documentation for a description of the functions supported by a component. You also need to refer to the component's documentation for information on the appropriate interface files that you must include to use the component (the interface files for the drawing component are shown beginning on Defining a Component's Interfaces ). The components that Apple provides with QuickTime are described in Inside Macintosh: QuickTime Components . As an example, drawing components support the following functions:

FUNCTION DrawerSetup(myInstance: ComponentInstance;
                            VAR r: Rect): ComponentResult;
FUNCTION DrawerClick(myInstance: ComponentInstance;
                            p: Point): ComponentResult;
FUNCTION DrawerMove (myInstance: ComponentInstance; x: Integer;
                            y: Integer): ComponentResult;
FUNCTION DrawerDraw (myInstance: ComponentInstance)
                            : ComponentResult;
FUNCTION DrawerErase(myInstance: ComponentInstance)
                            : ComponentResult;

© 1999 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next